home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / linuxconsole0.4.lcm / etc / postfix / postfix-script < prev   
Encoding:
Text File  |  2004-03-26  |  5.6 KB  |  241 lines

  1. #!/usr/bin/bash
  2.  
  3. #++
  4. # NAME
  5. #    postfix-script 1
  6. # SUMMARY
  7. #    execute Postfix administrative commands
  8. # SYNOPSIS
  9. #    \fBpostfix-script\fR \fIcommand\fR
  10. # DESCRIPTION
  11. #    The \fBpostfix-script\fR script executes Postfix administrative
  12. #    commands in an environment that is set up by the \fBpostfix\fR(1)
  13. #    command.
  14. # SEE ALSO
  15. #    master(8) Postfix master program
  16. #    postfix(1) Postfix administrative interface
  17. # LICENSE
  18. # .ad
  19. # .fi
  20. #    The Secure Mailer license must be distributed with this software.
  21. # AUTHOR(S)
  22. #    Wietse Venema
  23. #    IBM T.J. Watson Research
  24. #    P.O. Box 704
  25. #    Yorktown Heights, NY 10598, USA
  26. #--
  27.  
  28. # Avoid POSIX death due to SIGHUP when some parent process exits.
  29.  
  30. trap '' 1
  31.  
  32. case $daemon_directory in
  33. "") echo This script must be run by the postfix command. 1>&2
  34.     echo Do not run directly. 1>&2
  35.     exit 1
  36. esac
  37.  
  38. LOGGER="$command_directory/postlog -t $MAIL_LOGTAG/postfix-script"
  39. INFO="$LOGGER -p info"
  40. WARN="$LOGGER -p warn"
  41. ERROR="$LOGGER -p error"
  42. FATAL="$LOGGER -p fatal"
  43. PANIC="$LOGGER -p panic"
  44.  
  45. umask 022
  46. SHELL=/usr/bin/bash
  47.  
  48. #
  49. # Can't do much without these in place.
  50. #
  51. cd $command_directory || {
  52.     $FATAL no Postfix command directory $command_directory!
  53.     exit 1
  54. }
  55. cd $daemon_directory || {
  56.     $FATAL no Postfix daemon directory $daemon_directory!
  57.     exit 1
  58. }
  59. test -f master || {
  60.     $FATAL no Postfix master program $daemon_directory/master!
  61.     exit 1
  62. }
  63. cd $config_directory || {
  64.     $FATAL no Postfix configuration directory $config_directory!
  65.     exit 1
  66. }
  67. cd $queue_directory || {
  68.     $FATAL no Postfix queue directory $queue_directory!
  69.     exit 1
  70. }
  71.  
  72. #
  73. # Parse JCL
  74. #
  75. case $1 in
  76.  
  77. start_msg)
  78.  
  79.     echo "Start postfix"
  80.     ;;
  81.  
  82. stop_msg)
  83.  
  84.     echo "Stop postfix"
  85.     ;;
  86.  
  87. start)
  88.  
  89.     $daemon_directory/master -t 2>/dev/null || {
  90.         $FATAL the Postfix mail system is already running
  91.         exit 1
  92.     }
  93.     $config_directory/postfix-script check || {
  94.         $FATAL Postfix integrity check failed!
  95.         exit 1
  96.     }
  97.     $INFO starting the Postfix mail system
  98.     $daemon_directory/master &
  99.     ;;
  100.  
  101. drain)
  102.  
  103.     $daemon_directory/master -t 2>/dev/null && {
  104.         $FATAL the Postfix mail system is not running
  105.         exit 1
  106.     }
  107.     $INFO stopping the Postfix mail system
  108.     kill -9 `sed 1q pid/master.pid`
  109.     ;;
  110.  
  111. stop)
  112.  
  113.     $daemon_directory/master -t 2>/dev/null && {
  114.         $FATAL the Postfix mail system is not running
  115.         exit 1
  116.     }
  117.     $INFO stopping the Postfix mail system
  118.     kill `/usr/local/intranet/bin/sed 1q pid/master.pid`
  119.     ;;
  120.  
  121. abort)
  122.  
  123.     $daemon_directory/master -t 2>/dev/null && {
  124.         $FATAL the Postfix mail system is not running
  125.         exit 1
  126.     }
  127.     $INFO aborting the Postfix mail system
  128.     kill `/usr/local/intranet/bin/sed 1q pid/master.pid`
  129.     ;;
  130.  
  131. reload)
  132.  
  133.     $daemon_directory/master -t 2>/dev/null && {
  134.         $FATAL the Postfix mail system is not running
  135.         exit 1
  136.     }
  137.     $INFO refreshing the Postfix mail system
  138.     $command_directory/postsuper active || exit 1
  139.     kill -HUP `/usr/local/intranet/bin/sed 1q pid/master.pid`
  140.     $command_directory/postsuper &
  141.     ;;
  142.  
  143. flush)
  144.  
  145.     cd $queue_directory || {
  146.         $FATAL no Postfix queue directory $queue_directory!
  147.         exit 1
  148.     }
  149.     $command_directory/postqueue -f
  150.     ;;
  151.  
  152. check)
  153.  
  154.     for dir in $daemon_directory $config_directory $queue_directory
  155.     do
  156.         ls -lLd $dir | (grep " root " >/dev/null ||
  157.             $WARN not owned by root: $dir)
  158.     done
  159.  
  160.     /usr/local/intranet/bin/find $daemon_directory/* $config_directory/* ! -user root \
  161.         -exec $WARN not owned by root: {} \;
  162.  
  163.     /usr/local/intranet/bin/find $daemon_directory/. $config_directory/. \
  164.         \( -perm -020 -o -perm -002 \) -type f \
  165.         -exec $WARN group or other writable: {} \;
  166.  
  167.     $SHELL $config_directory/post-install create-missing || {
  168.         $WARN unable to create missing queue directories
  169.         exit 1
  170.     }
  171.  
  172.     /usr/local/intranet/bin/find `ls -d $queue_directory/* | \
  173.         egrep '/(incoming|active|defer|deferred|bounce|saved|corrupt|public|private|flush)$'` \
  174.         ! \( -type p -o -type s \) ! -user $mail_owner \
  175.         -exec $WARN not owned by $mail_owner: {} \;
  176.  
  177.     /usr/local/intranet/bin/find $queue_directory/public $queue_directory/maildrop \
  178.         $command_directory/postqueue $command_directory/postdrop \
  179.         -prune ! -group $setgid_group \
  180.         -exec $WARN not owned by group $setgid_group: {} \;
  181.  
  182.     /usr/local/intranet/bin/find $command_directory/postqueue $command_directory/postdrop \
  183.         -prune ! -perm -02111 \
  184.         -exec $WARN not set-gid: {} \;
  185.  
  186.     for name in `ls -d $queue_directory/* | \
  187.         egrep '/(bin|etc|lib|usr)$'` ; \
  188.     do \
  189.         /usr/local/intranet/bin/find $name ! -user root \
  190.         -exec $WARN not owned by root: {} \; ; \
  191.     done
  192.  
  193.     # WARNING: this should not descend into the maildrop directory.
  194.     # maildrop is the least trusted Postfix directory.
  195.  
  196.     /usr/local/intranet/bin/find $queue_directory/maildrop/. -prune ! -user $mail_owner \
  197.         -exec $WARN not owned by $mail_owner: $queue_directory/maildrop \;
  198.  
  199.     for dir in bin etc lib sbin usr
  200.     do
  201.         test -d $dir && /usr/local/intranet/bin/find $dir -type f -print | while read path
  202.         do
  203.             cmp -s $path /$path || 
  204.                 $WARN $queue_directory/$path and /$path differ
  205.         done
  206.     done
  207.  
  208.     # Look for incomplete installations.
  209.  
  210.     test -f $config_directory/master.cf || {
  211.         $FATAL no $config_directory/master.cf file found
  212.         exit 1
  213.     }
  214.  
  215.     # See if all queue files are in the right place. This is slow.
  216.     # We must scan all queues for mis-named queue files before the
  217.     # mail system can run.
  218.  
  219.     $command_directory/postsuper || exit 1
  220.  
  221.     /usr/local/intranet/bin/find corrupt -type f -exec $WARN damaged message: {} \;
  222.  
  223.     # XXX also: look for weird stuff, weird permissions, etc.
  224.  
  225.     test -f /usr/sbin/sendmail -a -f /usr/lib/sendmail && {
  226.         cmp -s /usr/sbin/sendmail /usr/lib/sendmail || {
  227.         $WARN /usr/lib/sendmail and /usr/sbin/sendmail differ
  228.         $WARN Replace one by a symbolic link to the other
  229.         }
  230.     }
  231.     exit 0
  232.     ;;
  233.  
  234. *)
  235.  
  236.     $FATAL "usage: postfix start (or stop, reload, abort, flush, or check)"
  237.     exit 1
  238.     ;;
  239.  
  240. esac
  241.